<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/context/mytags.jsp"%>
<t:base type="jquery,easyui,tools,DatePicker"></t:base>
<div class="easyui-layout" fit="true">
  <div region="center" style="padding:0px;border:0px">
  <t:datagrid name="deviceApplyList"  fitColumns="true" title="设备预约申请" actionUrl="deviceAppointApplyController.do?datagrid" idField="id" fit="true" >
  <t:dgCol title="主键"  field="id"  hidden="true"  queryMode="single"  width="120"></t:dgCol>
  <t:dgCol title="状态值"  field="applyStateValue"  hidden="true"  queryMode="single" width="80" ></t:dgCol>  
  <t:dgCol title="申请领取时间"  field="applyStartDate" formatter="yyyy-MM-dd hh:mm"   queryMode="single"  width="120"></t:dgCol> 
  <t:dgCol title="申请归还时间"  field="applyEndDate" formatter="yyyy-MM-dd hh:mm"   queryMode="single"  width="120"></t:dgCol>  
   <t:dgCol title="申请人"  field="applyUser.realName"   queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="品牌"  field="device.brand.brandName"   queryMode="single"  width="120"></t:dgCol> 
   <t:dgCol title="设备编号"  field="device.deviceNo"    queryMode="single"  width="120"></t:dgCol> 
   <t:dgCol title="型号"  field="device.model.modelName"    queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="申请状态"  field="applyState.name"    queryMode="single"  width="100"></t:dgCol>
   <t:dgCol title="领用说明"  field="remark"    queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="操作" field="opt" width="130"></t:dgCol>
   <t:dgDelOpt title="删除" url="deviceAppointApplyController.do?doDel&id={id}" exp="applyStateValue#eq#0,3"/>
   <t:dgFunOpt funname="submitApply(id)" title="提交申请" exp="applyStateValue#eq#0,3"></t:dgFunOpt> 
   <t:dgToolBar title="编辑" icon="icon-edit" url="deviceAppointApplyController.do?goUpdate" funname="updateApply"></t:dgToolBar>
   <t:dgToolBar title="查看" icon="icon-search" url="deviceAppointApplyController.do?goUpdate" funname="detail"></t:dgToolBar> 
  </t:datagrid>
  </div>
 </div><!--  -->
 <script type="text/javascript"> 
	function submitApply(id){
		$.dialog.confirm('确定要提交申请吗?', function(r) {
			   if (r) { 
					$.ajax({
						url : 'deviceAppointApplyController.do?submit&id='+id,
						type : 'post', 
						cache : false,
						success : function(data) {
 							var d = $.parseJSON(data);
							if (d.success) {
								var msg = d.msg; 
								reloadTable(); 
							} 
							tip(d.msg); 
						}
					});
				}
			});
		 
	}
	
	function updateApply() {
		gridname='deviceApplyList';
		var rowsData = $('#deviceApplyList').datagrid('getSelections');
		if (!rowsData || rowsData.length==0) {
			tip('请选择编辑项目');
			return;
		}
		if (rowsData.length>1) {
			tip('请选择一条记录再编辑');
			return;
		}
		
		var state = rowsData[0].applyStateValue;
		if(state == '0' || state =='3'){
			url = "deviceAppointApplyController.do?goUpdate";
			url += '&id='+rowsData[0].id; 
			createwindow('编辑信息',url,500,300);
		}else{
			tip("申请不能进行编辑！");
		}
		
		
	}
 </script>